#! /usr/bin/env bash
set -e

apt-get update
apt-get install -y curl git libpq-dev libsqlite3-dev libsasl2-dev postgresql-client postgresql postgresql-contrib sudo vim zlib1g-dev wget gnupg2
apt-get clean

wget -qO - https://apt.stellar.org/SDF.asc | apt-key add -
echo "deb https://apt.stellar.org/public stable/" | tee -a /etc/apt/sources.list.d/SDF.list
apt-get update
apt-get install -y stellar-core

wget https://dl.google.com/go/go1.13.6.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.13.6.linux-amd64.tar.gz

# configure postgres
service postgresql start
sudo -u postgres createdb core
sudo -u postgres createdb horizon

sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"

git clone https://github.com/stellar/go.git stellar-go
cd stellar-go
/usr/local/go/bin/go build -v ./services/horizon
